// miniprogram/pages/folder/folder.js
var httpUtils = require('../../utils/httpUtils');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mineContract: [{
        id: 1,
        title: "广大群众反馈步骤条问题",
        description: null,
        type: null,
        belong: 1,
        ossUrl: "https://he-contract.oss-cn-guangzhou.aliyuncs.com/2021/11/20/f2c3b121809d4940b4dc50f4378a7fb7.pdf",
        ipfsHash: null,
        state: 1,
        createTime: "2019-9-25 11:30"
      },
      {
        id: 2,
        title: "拾玖重构步骤条",
        description: null,
        type: null,
        belong: 1,
        ossUrl: "https://he-contract.oss-cn-guangzhou.aliyuncs.com/2021/11/20/f2c3b121809d4940b4dc50f4378a7fb7.pdf",
        ipfsHash: null,
        state: 3,
        createTime: "2019-10-05 12:30"
      },
      {
        id: 3,
        title: "步骤条更新完成😄",
        description: null,
        type: null,
        belong: 1,
        ossUrl: "https://he-contract.oss-cn-guangzhou.aliyuncs.com/2021/11/20/f2c3b121809d4940b4dc50f4378a7fb7.pdf",
        ipfsHash: null,
        state: 2,
        createTime: "2019-10-25 13:30"
      },
      {
        id: 3,
        title: "步骤条更新完成😄",
        description: null,
        type: null,
        belong: 1,
        ossUrl: "https://he-contract.oss-cn-guangzhou.aliyuncs.com/2021/11/20/f2c3b121809d4940b4dc50f4378a7fb7.pdf",
        ipfsHash: null,
        state: 2,
        createTime: "2019-10-25 13:30"
      },
      {
        id: 3,
        title: "步骤条更新完成😄",
        description: null,
        type: null,
        belong: 1,
        ossUrl: "https://he-contract.oss-cn-guangzhou.aliyuncs.com/2021/11/20/f2c3b121809d4940b4dc50f4378a7fb7.pdf",
        ipfsHash: null,
        state: 2,
        createTime: "2019-10-25 13:30"
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getContractList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 获取用户合同列表
   */
  getContractList(){
    wx.request({
      url: 'http://localhost:8080/system/contract/listByUserId',
      header:httpUtils.getHeader(),
      method:'GET',
      success:(res)=>{
        console.log(res);
        if(res.data!=null){
          this.setData({
            mineContract:res.data
          })
        }
      },
      fail:(err)=>{
        console.log(err);
      }
    })
  },

  /**
   * 查看pdf
   */
  showPDF:function(e){
    var url = e.currentTarget.dataset.url;
    wx.showToast({
      title: '打开中…',
      icon: "loading",
      duration: 100000
    })
    if (url) {
      wx.downloadFile({
        url: url,
        header: {
          'content-type': 'application/json',
        },
        // filePath: wx.env.USER_DATA_PATH + "/res",
        success: function (res) {
          console.log(res)
          var Path = res.tempFilePath //返回的文件临时地址，用于后面打开本地预览所用 
          wx.openDocument({
            filePath: Path,
            success: function (res) {
              wx.hideToast();
            }
          })
        },
        fail: function (res) {
          console.log(res);
          wx.showToast({
            title: '下载失败',
            icon: "loading",
            duration: 1000
          })
        }
      })
    }
  }
})